<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Ajax extends CI_Controller {   
function __construct() 
{
	parent::__construct();	
}
   function login() 
   { 
	$this->load->database();		
	$login = trim($this->input->post('login'));
	$pas = md5(trim($this->input->post('password')));
	$q = $this->db->query("SELECT reqid2u FROM inids WHERE login='$login' AND pass = '$pas' LIMIT 1");		
	$data['main'] = $q->result_array();	
	if ($this->db->affected_rows() == 0) $data = 0;		
		else {
			$part = $data['main'][0]['reqid2u'];
			$data = 1; 			
			$this->load->library('session');							
			$newdata = array(
                   'login'     => $login,
                   'password'  => $pas,
				   'reqid2u'   => $part,
                   'logged_in' => TRUE
               );
			$this->session->set_userdata($newdata);
		}
	echo json_encode($data);	 
	} 
}